﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;

namespace MyVoteMVC.Common.Specifications
{
    public class Specification<TEntity> : ISpecification<TEntity> where TEntity : class
    {
        private Expression<Func<TEntity, bool>> evalPredicate;
        private Func<TEntity, bool> evalFunc;

        #region ISpecification<TEntity> Members

        public Expression<Func<TEntity, bool>> EvalPredicate
        {
            get { return evalPredicate; }
        }

        public Func<TEntity, bool> EvalFunc
        {
            get { return evalFunc; }
        }

        #endregion

        public Specification(Expression<Func<TEntity, bool>> predicate)
        {
            evalPredicate = predicate;
        }

        private Specification() { }

        #region ISpecification<TEntity> Members


        public Expression<Func<TEntity, bool>> IsSatisfiedBy()
        {
            return evalPredicate;
        }

        #endregion
    }
}
